<html>

	<head>
		<title></title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="renderer" content="webkit">
		<title>站细管理系统</title>
		<link rel="stylesheet" type="text/css" href="/layuicms/layui/css/layui.css" />
		<!--<link rel="stylesheet" type="text/css" href="css/style2.css" />-->
		<link rel="stylesheet" type="text/css" href="/admin/css/style.css" />
		<link rel="stylesheet" href="/layuicms/layui_ext/dtree/dtree.css" media="all" />
		<link rel="stylesheet" href="/layuicms/layui_ext/dtree/font/dtreefont.css" media="all" />
		<script type="text/javascript" charset="utf-8" src="/admin/ueditor/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="/admin/ueditor/ueditor.all.js"></script>
		<script type="text/javascript" charset="utf-8" src="/admin/ueditor/lang/zh-cn/zh-cn.js"></script>
		<script type="text/javascript" src="/layuicms/layui_ext/dist/dtree.js"></script>
		<style type="text/css">
			.boxs {
				height: 100vh;
				overflow: hidden;
			}

			#edui1_iframeholder {
				overflow: hidden;
			}
			div #layui-layer2 .layui-layer layui-layer-page{
				z-index: 198910161; !important;
			}
		</style>
	</head>

	<body style="overflow: hidden;position: relative;">
		<div class="boxs">
			<div class="contentBox">
				<div class="contentLeft">
					<blockquote class="layui-elem-quote">
						<span id="updateTag" style="/* display: none; */"><b>修改编规</b></span>
						<a href="javascript:void(0)" id="removeOrg" onclick="closeToEditByZdid()"><i class="icon-x"></i></a>
					</blockquote>
					<div class="tree-list" style="overflow: auto;" id="toolbarDiv">
						<ul id="standTree" class="dtree" data-id="0" style="height: auto;"></ul>
					</div>
				</div>
				<form action="" method="post" class="layui-form" id="dataFrm" lay-filter="dataFrm">
				<div class="contentRight layui-row">
					<div class="layui-col-md8 newContext" id="newContext">
						<div class="new-box" style="">
							<div class="new-title">
								<span>新版</span>
							</div>
						<!--	<div class="imgTips">
								<span>图片支持png, jpg, jpeg, gif, bmp</span>
							</div>-->
							<div>
								<textarea name="remark" id="editor"  style="width:100%;height:auto;"></textarea>
							</div>
							<div class="e-action">
								<div id="dfzd">
									<button type="button" lay-submit="" class="layui-btn layui-btn-normal layui-btn-sm save-btn" id="doSubmit">保存修改</button>
								</div>
							</div>
						</div>
					</div>
				</div>
				</form>
			</div>
		</div>
		<script type="text/javascript" src="/layuicms/layui/layui.js"></script>
		<script type="text/javascript" src="/layuicms/layui_ext/dist/dtree.js"></script>
		<script type="text/javascript">
            layui.extend({
                dtree: '/layuicms/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
            }).use(['jquery','layer','dtree','layedit'], function() {
                var $ =  layui.jquery;
                var layer = layui.layer;
                var dtree = layui.dtree;
                var layedit = layui.layedit;
                var h=$(document).height()-100;
                var standTree;
                //创建一个编辑器  初始化富文本
                var editIndex = layedit.build('remark');
                //初始化富文本
                var ue = UE.getEditor('editor', {
                    initialFrameWidth: '100%',
                    initialFrameHeight: 680,
                    retainOnlyLabelPasted: false,
                    elementPathEnabled : false,
                    wordCount:false,
                	pasteplain: false,
                    toolbars: [
                        [
                            'source', //源代码
                            'undo', //撤销
                            'redo', //重做
                            'bold', //加粗
                            'selectall', //全选
                            'preview', //预览
                            'horizontal', //分隔线
                            'removeformat', //清除格式
                            'simpleupload', //单图上传
                            'insertimage', //多图上传
                            'inserttable', //插入表格
                            'edittable', //表格属性
                            'emotion', //表情
                            'spechars', //特殊字符
                            'searchreplace', //查询替换
                            'justifyleft', //居左对齐
                            'justifyright', //居右对齐
                            'justifycenter', //居中对齐
                            'justifyjustify', //两端对齐
                            'forecolor', //字体颜色
                            'fullscreen', //全屏
                            'attachment', //附件
                        ]
                    ],
                    autoHeightEnabled: true,
                    autoFloatEnabled: true,
                    zIndex: 19891015
                });

                ue.ready(function() {
                    ue.setHeight(h);
                });
                // 初始化树
                standTree = dtree.render({
                    elem: "#standTree",
                    dataStyle: "layuiStyle",
                    dataFormat: "list",  //配置data的风格为list
                    response: {message: "msg", statusCode: 0},
                    initLevel: "1",
                    icon: "2",
                    toolbar: true,
                    record: true,
                    line: true,
                    scroll:"#toolbarDiv",
                    url: '/standFile/loadStandManagerLeftJson', // 使用url加载（可与data加载同时存在）
                    toolbarFun: {
                        loadToolbarBefore: function (buttons, param, $div) {
                            if (param.context=="正文") { // 如果是叶子节点
                                buttons.delToolbar = "";
                                buttons.addToolbar = "";
                                buttons.editToolbar = "";// 取消新增功能
                            }
                        //    UE.getEditor('editor').destroy();
                            return buttons; // 将按钮对象返回
                        },
                        addTreeNode: function (treeNode, $div) {
                            var jsonData = JSON.stringify(treeNode);
                            $.ajax({
                                type: "post",
                                data: {data: jsonData},
                                url: "/standFile/addStand",
                                success: function (result) {
                                    //standTree.changeTreeNodeAdd(treeNode.nodeId); // 添加成功，返回ID
                                    standTree.changeTreeNodeAdd(true); // 添加成功
                                    //standTree.changeTreeNodeAdd(result.data); // 添加成功，返回一个JSON对象
                                    standTree.changeTreeNodeAdd("refresh"); // 添加成功，局部刷新树
                                },
                                error: function () {
                                    standTree.changeTreeNodeAdd(false); // 添加失败
                                }
                            });
                        },
                        editTreeNode: function (treeNode, $div) {
                            var jsonData = JSON.stringify(treeNode);
                            $.ajax({
                                type: "post",
                                data: {data: jsonData},
                                url: "/standFile/updateStand",
                                success: function (result) {
                                    standTree.changeTreeNodeEdit(true);// 修改成功
                                    //DTree1.changeTreeNodeEdit(result.param); // 修改成功，返回一个JSON对象
                                },
                                error: function () {
                                    //DTree1.changeTreeNodeEdit(false);//修改失败
                                }
                            });
                        },
                        delTreeNode: function (treeNode, $div) {
                            var jsonData = JSON.stringify(treeNode);
                            $.ajax({
                                type: "post",
                                data: {data: jsonData},
                                url: "/standFile/deleteStand",
                                success: function (result) {
                                    standTree.changeTreeNodeDel(true); // 删除成功
                                },
                                error: function () {
                                    //DTree1.changeTreeNodeDel(false);// 删除失败
                                }
                            });
                        }
                    }

                });
                // 绑定节点点击
				var url = "";
				var id = "";
                dtree.on("node('standTree')" ,function(obj){
                    $.ajax({
                        type: "post",
                        data: {nodeId: obj.param.nodeId},
                        url: "/standFile/findStandTree",
                        success: function (result) {
                            var ue = UE.getEditor('editor');
                            var proinfo=result.data.item.remark;
							url="/standFile/updateStandById/"+obj.param.nodeId;
							id = obj.param.nodeId;
							if(null!=proinfo){
                                ue.ready(function() {//编辑器初始化完成再赋值
                                    ue.setContent(proinfo);  //赋值给UEditor
                                });
							}else {
                                ue.ready(function() {//编辑器初始化完成再赋值
                                    ue.setContent("");  //赋值给UEditor
                                });
							}
                        }
                    });
                });
                $("#doSubmit").click(function () {
                    //同步富文本和textarea里面的内容
                    layedit.sync(editIndex)
                    var data = $("#dataFrm").serialize();
                    $.post(url,data,function (res) {
                        if(res.code==20000){
                            /*tableIns.reload();*/
                        }
                        layer.msg(res.message);
                        layer.close(mainIndex);
                    })
                });
            });
		</script>
	</body>
</html>